<?php

define('LOCATION_ACC_PARENT', 'object');
define('LOCATION_ACC_SUBTYPE', 'location_acc');
define('LOCATION_ACC_CLASS', 'LocationAccount');

define('LOCATION_ACC_LATTITUDE', 'lattitude');
define('LOCATION_ACC_LONGTITUDE', 'longtitude');
define('LOCATION_ACC_ACCURACY', 'accuracy');
define('LOCATION_ACC_CLIENT_ID', 'client_id');

register_entity_type(LOCATION_ACC_PARENT, LOCATION_ACC_SUBTYPE);
// This operation only affects the db on the first call for this subtype
// If you change the class name, you'll have to hand-edit the db
add_subtype(LOCATION_ACC_PARENT, LOCATION_ACC_SUBTYPE, LOCATION_ACC_CLASS);

class FacebookAccount extends ElggObject {

    protected function initialise_attributes() {
        parent::initialise_attributes ();
        $this->attributes ['subtype'] = LOCATION_ACC_SUBTYPE;
        $this->access_id = ACCESS_PUBLIC;
    }

    public function __construct($guid = null) {
        parent::__construct($guid);
    }

    public function setOwner($guid) {
        $this->owner_guid = $guid;
        $this->save();
    }

    // more customizations here
    public function saveAccount($lattitude, $longtitude, $accuracy, $client_id) {
        $this->save();
        $this->setMetaData('greengar_account', 1);
        $this->setMetaData(LOCATION_ACC_LATTITUDE, $lattitude, 'integer');
        $this->setMetaData(LOCATION_ACC_LASTNAME, $longtitude, 'integer');
        $this->setMetaData(LOCATION_ACC_HOMETOWN, $accuracy, 'integer');
        $this->setMetaData(LOCATION_ACC_CLIENT_ID, $client_id, 'text');
        return $this->save();
    }

    public function toArray() {
        return array(
            'guid' => $this->getGUID(),
            'lattitude' => $this->lattitude,
            'longtitude' => $this->longtitude,
            'accuracy' => $this->accuracy,
            'type' => 'Location'
        );
    }

}

?>